package com.ruoyi.buss.qmcy.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.buss.utils.DateUtilss;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.buss.qmcy.mapper.QmcyCustDkjgMapper;
import com.ruoyi.buss.qmcy.domain.QmcyCustDkjg;
import com.ruoyi.buss.qmcy.service.IQmcyCustDkjgService;

/**
 * 贷款结构趋势Service业务层处理
 * 
 * @author sxy
 * @date 2021-07-16
 */
@Service
public class QmcyCustDkjgServiceImpl implements IQmcyCustDkjgService 
{
    @Autowired
    private QmcyCustDkjgMapper qmcyCustDkjgMapper;

    /**
     * 查询贷款结构趋势
     * 
     * @param etlDt 贷款结构趋势ID
     * @return 贷款结构趋势
     */
    @Override
    public QmcyCustDkjg selectQmcyCustDkjgById(String etlDt)
    {
        return qmcyCustDkjgMapper.selectQmcyCustDkjgById(etlDt);
    }

    /**
     * 查询贷款结构趋势列表
     * 
     * @param qmcyCustDkjg 贷款结构趋势
     * @return 贷款结构趋势
     */
    @Override
    public List<QmcyCustDkjg> selectQmcyCustDkjgList(QmcyCustDkjg qmcyCustDkjg, LoginUser userInfo)
    {
        List<QmcyCustDkjg> doList = new ArrayList<QmcyCustDkjg>();
        /**
         * 判断数据日期是否为近3年4个季度以及当年每个月月末
         */
        ArrayList<String> sjrqs = DateUtilss.getThreeYearFourQuarterAndMonth();
        if (!StringUtils.isEmpty(qmcyCustDkjg.getSjrq())) {
            if ("9999".equals(qmcyCustDkjg.getSjrq())) {
                qmcyCustDkjg.setSjrq("");
            }
            sjrqs = new ArrayList<String>();
            String sjrq = qmcyCustDkjg.getSjrq();
            sjrq = sjrq.replace("-", "");
            sjrqs.add(sjrq);
        }

        /**
         * 加入昨天的数据
         */
        sjrqs.add(DateUtils.getBefoDate(1)) ;
        qmcyCustDkjg.setSjrqs(sjrqs);
        // 1是正序 0是倒序
        if (qmcyCustDkjg.getType() == 1) {
            doList = qmcyCustDkjgMapper.dkjg(qmcyCustDkjg);
        } else if (qmcyCustDkjg.getType() == 0) {
            doList = qmcyCustDkjgMapper.dkjg(qmcyCustDkjg);
            // 3是导出
        } else if (qmcyCustDkjg.getType() == 3) {
            doList = qmcyCustDkjgMapper.dkjg(qmcyCustDkjg);
        }
        
        return doList;
    }

    /**
     * 新增贷款结构趋势
     * 
     * @param qmcyCustDkjg 贷款结构趋势
     * @return 结果
     */
    @Override
    public int insertQmcyCustDkjg(QmcyCustDkjg qmcyCustDkjg)
    {
        return qmcyCustDkjgMapper.insertQmcyCustDkjg(qmcyCustDkjg);
    }

    /**
     * 修改贷款结构趋势
     * 
     * @param qmcyCustDkjg 贷款结构趋势
     * @return 结果
     */
    @Override
    public int updateQmcyCustDkjg(QmcyCustDkjg qmcyCustDkjg)
    {
        return qmcyCustDkjgMapper.updateQmcyCustDkjg(qmcyCustDkjg);
    }

    /**
     * 批量删除贷款结构趋势
     * 
     * @param etlDts 需要删除的贷款结构趋势ID
     * @return 结果
     */
    @Override
    public int deleteQmcyCustDkjgByIds(String[] etlDts)
    {
        return qmcyCustDkjgMapper.deleteQmcyCustDkjgByIds(etlDts);
    }

    /**
     * 删除贷款结构趋势信息
     * 
     * @param etlDt 贷款结构趋势ID
     * @return 结果
     */
    @Override
    public int deleteQmcyCustDkjgById(String etlDt)
    {
        return qmcyCustDkjgMapper.deleteQmcyCustDkjgById(etlDt);
    }
}
